package conf

import (
	"encoding/json"
	"io/ioutil"
)

var Conf struct {
	Port             string
	JwtSecret        string
	Mysql            string
	EnvDevelopment   bool
	CdkWorkerNum     int
	WorkerChanLength int
	TimeOutSecond    int // use cdk请求超时时间

	Redis struct {
		Db                int
		PassWord          string
		Host              string
		DefaultExpiration int
	}

	AgentList map[string]*AgentInfo

	CorpId         string
	Token          string
	EncodingAESKey string

	LoginRedirectUri string

	// 报警
	WarnConfig struct {
		PartyId  string  // 报警部门id
		Duration float64 // 报警最短间隔
		Url      string  // 报警地址
	}
}

// 企业微信应用信息
type AgentInfo struct {
	AgentId int
	Secret  string
	Desc    string
}

func LoadConfig(file string) error {
	data, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}
	err = json.Unmarshal(data, &Conf)
	if err != nil {
		return err
	}
	return nil
}

func init() {
	if err := LoadConfig("conf.json"); err != nil {
		panic(err)
	}
}
